package com.allwees.bs.c.module.order.entity;

import com.allwees.bs.c.module.order.req.OrderReviewReq;
import com.allwees.bs.c.module.user.entity.UserEntity;
import com.allwees.bs.core.model.order.entity.OrderReviewItemModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * 订单项评价
 *
 * @author jy2016
 */
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@Entity()
@Table(name = "o_order_reviews_item")
public class OrderReviewItemEntity extends OrderReviewItemModel {

	public OrderReviewItemEntity(OrderReviewReq reviewReq, OrderItemEntity orderItem, UserEntity user) {
    	this();
    	this.setOrderUuid(reviewReq.getOrderUuid());
    	this.setProductUuid(orderItem.getProductUuid());
    	this.setSkuUuid(orderItem.getSkuUuid());
    	this.setRating(reviewReq.getRating());
    	this.setText(reviewReq.getText());
    	updateReviewUserInfo(user);
        //订单评价初始状态0，待审核
    	this.setPhotos(StringUtils.join(reviewReq.getPhotos(), ","));
    }

	private void updateReviewUserInfo(UserEntity user) {
		this.setUserUuid(user.getUuid());
		this.setUserEmail(user.getEmail());
		this.setUserAvatar(user.getAvatar());
		this.setUserFirstName(user.getFirstName());
		this.setUserLastName(user.getLastName());
		this.setUserCountry(user.getCountry());
		this.setUserLanguage(user.getLanguage());
		this.setUserPhone(user.getPhone());
	}
}
